
\documentclass{beamer}


\mode<presentation>
{
  \usetheme{CambridgeUS}
	\usecolortheme{beaver}
  % or ...

  \setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}


\usepackage{xeCJK}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{pifont}
\usepackage{bibentry}
\usepackage{verbatim}
\usepackage{color}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\setCJKmainfont{WenQuanYi Micro Hei}
\renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
\raggedright

\let\oldfootnotesize\footnotesize
\renewcommand*{\footnotesize}{\oldfootnotesize\tiny}


\title[Python 连接MongoDB（外一则）] 
{Python 连接MongoDB（外一则）}

\author[Zhilei Ren] 
{Zhilei Ren}

\institute[OSCAR Team] % (optional, but mostly needed)
{
\\\includegraphics[width=0.2\textwidth]{../utils/logo.jpg}\\
OSCAR Team, School of Software, 
Dalian University of Technology
}


\subject{MongoDB}



\pgfdeclareimage[height=0.5cm]{university-logo}{../utils/logo.jpg}
\logo{\pgfuseimage{university-logo}}



% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
\AtBeginSubsection[]
{
  \begin{frame}<beamer>{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}

\setbeamertemplate{section in toc}[circle]
\setbeamertemplate{items}[circle]
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{bibliography item}{\insertbiblabel}
\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry journal}{}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

%\begin{frame}{Outline}
%  \tableofcontents[currentsection,currentsubsection, 
%    hideothersubsections, 
%    sectionstyle=show,
%]
%\end{frame}

\AtBeginSection[]
{
 \begin{frame}<beamer>
 \frametitle{Outline}
 \tableofcontents[currentsection]
 \end{frame}
}
\section{与Git托管仓库交互} % (fold)
\label{sec:与Git托管仓库交互}
\begin{frame}
  \frametitle{新建仓库}
	\centering
	\includegraphics[width=.6\textwidth]{new.png}
\end{frame}

\begin{frame}
  \frametitle{填写信息}
	\centering
	\includegraphics[width=.6\textwidth]{info.png}
\end{frame}

\begin{frame}
  \frametitle{更多信息}
	\centering
	\includegraphics[width=.6\textwidth]{info2.png}
\end{frame}

\begin{frame}
  \frametitle{推送仓库}
	\centering
	\includegraphics[width=.6\textwidth]{cmd.png}
\end{frame}
% section 与Git托管仓库交互 (end)

\section{基于pymongo的数据库连接}
\begin{frame}[t,fragile]{pymongo安装}
	\begin{block}{}
		\begin{itemize}
			\item via pip
\begin{verbatim}
$pip install pymongo
\end{verbatim}
			\item via distro (e.g., apt)
\begin{verbatim}
$sudo apt-get install python-pymongo
\end{verbatim}
		\end{itemize}
	\end{block}
\end{frame}

\begin{frame}[t,fragile]{pymongo API使用}
	\begin{block}{Python snippet}
		\scriptsize
\begin{verbatim}
import pymongo
from pymongo import MongoClient
client = MongoClient()

# Get the sampleDB database
db = client.sampleDB 
# equivalently, use db = client['sampleDB']
coll = db.sampleCollection
# equivalently, use coll = db['sampleCollection']
#CRUD: Create
coll.insert_one({"id": 123, "name": "zhangsan", "age": 18})
coll.insert_one({"id": 124, "name": "lisi", "age": 17})
#CRUD: Retrieve
for entry in coll.find():
    print("id: %d, name: %s, age: %d" % 
          (entry['id'], entry['name'], entry['age']))
\end{verbatim}
	\end{block}
\end{frame}

\begin{frame}[t,fragile]{pymongo API使用}
	\begin{block}{Python snippet}
		\scriptsize
\begin{verbatim}
#CRUD: Update
col.update({"age": {"$lt": 20}}, {"$inc": {"age": 1}})
#{u'n': 1, u'nModified': 1, u'ok': 1, 'updatedExisting': True}
col.update({"age": {"$lt": 20}}, {"$inc": {"age": 1}}, multi=True)
#{u'n': 2, u'nModified': 2, u'ok': 1, 'updatedExisting': True}
#CRUD: Delete
col.remove({"age": {"$gt": 10}})
#{u'n': 2, u'ok': 1}
coll.insert_one({"id": 123, "name": "zhangsan", "age": 18})
coll.insert_one({"id": 124, "name": "lisi", "age": 17})
col.remove({"age": {"$gt": 10}}, multi=False)
#{u'n': 1, u'ok': 1}
\end{verbatim}
	\end{block}
\end{frame}

\begin{frame}
	\vspace{3cm}
	\Huge
	Thanks
	\vspace{2cm}
	\normalsize
	\flushright
		Zhilei Ren

		zren@dlut.edu.cn
	
\end{frame}
\end{document}
